home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / dbleAEPBAL.cc < prev    next >
C/C++ Source or Header  |  1996-03-03  |  2KB  |  101 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include <string>
  32.  
  33. #include "dbleAEPBAL.h"
  34. #include "f77-fcn.h"
  35.  
  36. extern "C"
  37. {
  38.   int F77_FCN (dgebal, DGEBAL) (const char*, const int&, double*,
  39.                 const int&, int&, int&, double*,
  40.                 int&, long, long);
  41.  
  42.   int F77_FCN (dgebak, DGEBAK) (const char*, const char*, const int&,
  43.                 const int&, const int&, double*,
  44.                 const int&, double*, const int&,
  45.                 int&, long, long);
  46. }
  47.  
  48. int
  49. AEPBALANCE::init (const Matrix& a, const string& balance_job)
  50. {
  51.   int n = a.cols ();
  52.  
  53.   if (a.rows () != n)
  54.     {
  55.       (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix");
  56.       return -1;
  57.     }
  58.  
  59.   int info;
  60.   int ilo;
  61.   int ihi;
  62.  
  63.   Array<double> scale (n);
  64.   double *pscale = scale.fortran_vec ();
  65.  
  66.   balanced_mat = a;
  67.   double *p_balanced_mat = balanced_mat.fortran_vec ();
  68.  
  69.   char job = balance_job[0];
  70.  
  71.   F77_XFCN (dgebal, DGEBAL, (&job, n, p_balanced_mat, n, ilo, ihi,
  72.                  pscale, info, 1L, 1L));
  73.  
  74.   if (f77_exception_encountered)
  75.     (*current_liboctave_error_handler) ("unrecoverable error in dgebal");
  76.   else
  77.     {
  78.       balancing_mat = Matrix (n, n, 0.0);
  79.       for (int i = 0; i < n; i++)
  80.     balancing_mat.elem (i ,i) = 1.0;
  81.  
  82.       double *p_balancing_mat = balancing_mat.fortran_vec ();
  83.  
  84.       char side = 'R';
  85.  
  86.       F77_XFCN (dgebak, DGEBAK, (&job, &side, n, ilo, ihi, pscale, n,
  87.                  p_balancing_mat, n, info, 1L, 1L));
  88.  
  89.       if (f77_exception_encountered)
  90.     (*current_liboctave_error_handler) ("unrecoverable error in dgebak");
  91.     }
  92.  
  93.   return info;
  94. }
  95.  
  96. /*
  97. ;;; Local Variables: ***
  98. ;;; mode: C++ ***
  99. ;;; End: ***
  100. */
  101.